# -*- coding: utf-8 -*- 
# @project : 《Atcoder》
# @Author : created by bensonrachel on 2021/7/26
# @File : （step2）H. Hamburgers（CF）.py
# https://codeforces.com/edu/course/2/lesson/6/2/practice/contest/283932/problem/H

def re(str):
    b = 0
    s = 0
    c = 0
    for i in str:
        if (i == "B"):
            b += 1
        if (i == "S"):
            s += 1
        if (i == "C"):
            c += 1
    return (b, s, c)

def check(mid, t, r): #应该是判断要做成当前这么多个汉堡时够不够钱。而不用材料数做对比，因为这样你还要想这么多钱怎么买才能做成最多的汉堡
    global nb, ns, nc, pb, ps, pc #因为比较钱的话就是算满足做当前这么多个汉堡需要多少钱，比较材料的话就还要分开b s c来比较材料是否够，还要想怎么分配r去买东西。
    b = (mid * t[0] - nb) * pb
    s = (mid * t[1] - ns) * ps
    c = (mid * t[2] - nc) * pc
    if (b < 0): b = 0#小于0说明厨房够这种食材，不用买
    if (s < 0): s = 0
    if (c < 0): c = 0
    need_money = b + s + c
    return need_money <= r #比较是否够钱即可

def bi(t, x):
    l = 0
    r = 1e13
    while (l + 1 < r):
        mid = (l + r) // 2
        if (check(mid, t, x)):#二分的难点就是写check函数，即判断条件，好难啊
            l = mid
        else:
            r = mid
    return l

if __name__ == "__main__":
    str_h = input()
    nb, ns, nc = map(int, input().split())
    pb, ps, pc = map(int, input().split())
    r = int(input())
    t = re(str_h)
    print(int(bi(t, r)))


